package com.wyiot.pet.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wyiot.pet.model.entity.UserDO;
import com.wyiot.pet.model.vo.UserVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;

/**
 * @author yly
 * @since 2022/3/24
 */
@Mapper
public interface UserMapper extends BaseMapper<UserDO> {

    /** 查找用户对应的密码 */
    @Select(" SELECT user_id , user_code ,user_password , user_type, user_name,user_phone ,user_status,last_login_time , user_lock_time  FROM pet_user WHERE user_code = #{userCode}")
    UserVO selectUserByCode(String userCode);

    @Select("select count(user_code) from pet_user where user_code = #{userCode}")
    boolean isUserCodeExist(@Param("userCode") String userCode);

    @Select("select count(user_phone) from pet_user where user_code = #{userPhone}" )
    boolean isUserPhoneExist(@Param("userPhone") String userPhone);
//    List<UserDO> queryUserAllInfoById(Long userId);
    /**
     * 更新用户锁定时间
     */
    @Update("update pet_user set user_lock_time=#{lockTime} where user_id=#{userId}")
    void updateLocktimeById(@Param("lockTime") Date lockTime, @Param("userId") Long userId);

    /*通过手机号找到用户*/
    @Select("select * from pet_user where user_phone = #{phone}")
    UserDO getUserIdByUserPhone(@Param("phone") String Phone);


}
